package org.gnomus.server.controllers;

import org.gnomus.server.C;
import org.gnomus.server.Context;
import org.gnomus.server.Controller;
import org.gnomus.util.servlet;

import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;

public class Access implements Controller {

    public static void enqueue(int sc) {
        Context ctx = Context.get();
        if (C.ENABLE_ACCESS_LOG && !C.ACCESS_LOG_URI.equalsIgnoreCase(ctx.uri) &&
            !C.APPENGINE_UA.toLowerCase().equals(ctx.ua.toLowerCase())) {
            servlet.enqueue(withUrl(C.ACCESS_LOG_URI).
                    param("uri", ctx.uri).
                    param("query", ctx.query == null ? "" : ctx.query).
                    param("ua", ctx.ua).
                    param("ip", ctx.ip).
                    param("sc", "" + sc));
        }
    }
}